/*
 * User: user
 * Date: 25/12/2007
 * Time: 01:44:22
 */
package org.conann.instrument;

import javassist.*;
import org.conann.metadata.RecordsRegistry;
import org.conann.metadata.records.TypeRecord;
import org.conann.util.DevelopmentUtil;

public class ClassIntrumentor implements Intrumentor<Class<?>> {

    private final RecordsRegistry registry;

    public ClassIntrumentor(RecordsRegistry registry) {
        this.registry = registry;
    }

    public void instrument(Class<?> element) {
//        TypeRecord<?> record = registry.getRecord(element);
//        Set<Annotation> bindingAnnotations = record.getComponentMD().getBindingTypes();
//        Set<FieldRecord> fields = record.GetFields();
//        for (FieldRecord field : fields) {
//            Set<Annotation> fieldBindingAnnotations = field.getComponentMD().getBindingTypes();
//        }
//
//        Set<MethodRecord> methods = record.getMethods();

        CtClass ctClass = CtUtil.getCtClass(element);

        CtConstructor ctConstructor = ctClass.getClassInitializer();
        CtUtil.insertAfter(ctConstructor, "_initializeComponent();");

        throw DevelopmentUtil.unsupportedOperation();
    }

    private CtMethod createInitializationMethod(TypeRecord<?> record) {
        Class<?> type = record.getType();
        CtClass ctClass = CtUtil.getCtClass(type);
        String sourceCode = null;
        try {
            return CtNewMethod.make(Modifier.PRIVATE, null, "_initializeComponent", new CtClass[]{}, null, sourceCode, ctClass);
        } catch (CannotCompileException e) {
            e.printStackTrace();
        }
        throw DevelopmentUtil.unsupportedOperation();
    }
}